# -*- coding: utf-8 -*-

import cv2
import numpy as np
from matplotlib import pyplot as plt

#梯度=膨胀-腐蚀
pie = cv2.imread('pie.png')
kernel = np.ones((7,7),np.uint8)
# erosion = cv2.erode(pie,kernel,iterations=5)
# dilate = cv2.dilate(pie,kernel,iterations=5)
gradient = cv2.morphologyEx(pie,cv2.MORPH_GRADIENT,kernel)

res = np.hstack((pie, gradient))
cv2.imshow('erosion', res)
cv2.imwrite('gradient.png', res)
#gradient为原图、梯度运算对比图
cv2.waitKey(0)
cv2.destroyAllWindows()